<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../../inc.jsp"></jsp:include>
<script type="text/javascript" charset="utf-8">
	var datagrid;//列表对象

	/**
	*加载列表
	**/
	$(function loadDatagrid() {
		datagrid = $('#datagrid').datagrid({
			url : 'jueSeAction!datagrid.action',
			title : '',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [ 10, 20, 30, 40 ],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : false,
			idField : 'bianHao',
	//		sortName : 'id',
	//		sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			singleSelect : true,
	//		frozenColumns : [ [ 
			columns : [ [ //字段定义
    		{
				title : '<s:text name="bianHao"></s:text>',
				field : 'bianHao',
				width : 150,
				sortable : true,
				checkbox : true
			}
			,{
				title : '<s:text name="jueSeMC"></s:text>',
				field : 'jueSeMC',
				width : 150,
				formatter: function(value,obj,rowNum){  
  					return "<a href='javascript:void(0);view("+rowNum+")'>"+value+"<a>";  
				}
			},{
				title : '<s:text name="zhuangTai"></s:text>',
				field : 'zhuangTaiStr',
				width : 150
			},{
				title : '<s:text name="shunXu"></s:text>',
				field : 'shunXu',
				width : 150
			},{
				title : '<s:text name="chuangJianSJ"></s:text>',
				field : 'chuangJianSJ',
				width : 150
			}
			] ],
			toolbar : [ { //工具栏定义
				text : '<s:text name="add"></s:text>',
				iconCls : 'icon-add',
				handler : function() {
					append();
				}
			}, '-', {
				text : '<s:text name="edit"></s:text>',
				iconCls : 'icon-edit',
				handler : function() {
					edit();
				}
			/*}, '-', {
				text : '<s:text name="delete"></s:text>',
				iconCls : 'icon-remove',
				handler : function() {
					remove();
				}*/
			}, '-'],
			onRowContextMenu : function(e, rowIndex, rowData) {//右键菜单定义
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});

	});
	
	/**
	*查看
	**/
	function view(rowNum) {
		var rows = datagrid.datagrid("getRows");
		var node = rows[rowNum];
		var p = parent.dagong.dialog({
			title : '查看角色',
			href : 'jueSeAction!jueSeView.action',//加载页面
			width : 450,
			height : 310,
			buttons : [ {
				text : '<s:text name="guanBi"></s:text>',
				handler : function() {
					p.dialog('close');
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				parent.$.messager.progress('close');
				f.form('load', node);
			}
		});
	}
	
	/**
	*添加
	**/
	function append() {
		var p = parent.dagong.dialog({
			title : '添加角色',
			href : 'jueSeAction!jueSeAdd.action',
			width : 420,
			height : 230,
			buttons : [ {
				text : '<s:text name="add"></s:text>',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : 'jueSeAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.dagong.messagerShow({
								msg : json.msg,
								title : '<s:text name="prompt"></s:text>'
							});
						}
					});
				}
			} ,{
				text : '<s:text name="guanBi"></s:text>',
				handler : function() {
					p.dialog('close');
				}
			}],
			onLoad : function() {
				var f = p.find('form');
				var zhuangTai = f.find('input[name=zhuangTai]');
				var iconCombo = zhuangTai.combobox({//加载下拉菜单
					url : 'mainAction!cache.action?cacheKey=ZhuangTai',
					valueField : 'detailID',
					textField : 'detailName',
					editable : false,
					panelHeight : 'auto',
					onLoadSuccess : function(){
						zhuangTai.combobox('select','11');
					}
				});
				
				var gongNengBH = f.find('input[name=gongNengBH]');
				var gongNengtree = gongNengBH.combotree({
					url : 'gongNengAction!tree.action',
					lines : true,
					multiple : true,
					checkbox : true,
					cascadeCheck : false
				});
			}
			
		});
	}
	
	/**
	*修改
	**/
	function edit() {
		var rows = datagrid.datagrid('getChecked');//获取选中行
		if (rows.length == 1) {//选中一行
			var node = rows[0];
			var p = parent.dagong.dialog({
				title : '修改角色',
				href : 'jueSeAction!jueSeEdit.action?bianHao='+node.bianHao,//加载edit页面
				width : 420,
				height : 230,
				buttons : [ {
					text : '<s:text name="edit"></s:text>',
					handler : function() {
						var f = p.find('form');
						f.form('submit', {
							url : 'jueSeAction!edit.action',
							onSubmit: function(){   
								if(f.find("input[id='ff']").val()=="haveElements")	return false;
							},   
							success : function(d) {
								var json = $.parseJSON(d);
								if (json.success) {
									datagrid.datagrid('reload');
									p.dialog('close');
								}
								parent.dagong.messagerShow({
									msg : json.msg,
									title : '<s:text name="prompt"></s:text>'
								});
							}
						});
					}
				} ,{
					text : '<s:text name="guanBi"></s:text>',
					handler : function() {
						p.dialog('close');
					}
				}],
				onLoad : function() {
					var f = p.find('form');
					/*var zhuangTai = f.find('input[name=zhuangTai]');
					var iconCombo = zhuangTai.combobox({//加载下拉菜单
						url : 'mainAction!cache.action?cacheKey=ZhuangTai',
						valueField : 'detailID',
						textField : 'detailName',
						editable : false,
						panelHeight : 'auto',
						onSelect : function(){
							var value = zhuangTai.combobox('getValue');
							if(value=="11"){
								
							}else if(value=="12"){
								$(".dialog-button a").attr("disabled",true);
							}
						}
					});*/
					
					var gongNengBH = f.find('input[name=gongNengBH]');
					var gongNengtree = gongNengBH.combotree({
						url : 'gongNengAction!tree.action',
						lines : true,
						multiple : true,
						checkbox : true,
						cascadeCheck : false
					});
					parent.$.messager.progress('close');
					gongNengBH.combotree('setValues', [1,2,3]);
					f.form('load', {
						bianHao :node.bianHao,
						jueSeMC : node.jueSeMC,
						shunXu : node.shunXu,
						zhuangTai : node.zhuangTai,
						chuangJianSJ : node.chuangJianSJ,
						note : node.note,
						gongNengBH : dagong.getList(node.gongNengBH)
					});
				}
			});
		} else if (rows.length > 1) {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseSelectARecord"></s:text>', 'error');
		} else {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseTickToEditRecords"></s:text>', 'error');
		}
	}

	/**
	*删除
	**/
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.dagong.messagerConfirm('<s:text name="pleaseConfirm"></s:text>', '<s:text name="DoYouWantToDeleteTheSelectedItem"></s:text>', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].bianHao);
					}
					$.ajax({
						url : 'jueSeAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							parent.dagong.messagerShow({
								title : '<s:text name="prompt"></s:text>',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseTickToDeleteRecords"></s:text>', 'error');
		}
	}
	
	$(function loadZhuangTai() {
		var sf = $('#searchForm');
		var zhuangTai = sf.find('input[name=zhuangTai]');
		var iconCombo1 = zhuangTai.combobox({//加载下拉菜单
			url : 'mainAction!cache.action?cacheKey=ZhuangTai',
			valueField : 'detailID',
			textField : 'detailName',
			editable : false,
			panelHeight : 'auto',
			onLoadSuccess : function(){
			
			}
		});
	});
	
	/**
	* 提交查询
	**/
	function _search() {
		if ($("#searchForm").form('validate')) { //验证特殊字符
			datagrid.datagrid('load', dagong.serializeObject($('#searchForm')));
		}
	}
	
	/**
	* 清空查询条件
	**/
	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
		$('#zhuangTai').combobox('select','');
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true">

	<div data-options="region:'north',border:false,title:'查询条件'" style="height:90px;overflow: hidden;" >
		<form id="searchForm">
		<!--  
			<table class="tableForm datagrid-toolbar" style="width: 100%;height: 100%;">
				<tr>
					<th>用户名</th>
					<td><input name="shiTiBH" style="width:317px;" /></td>
				</tr>
				<tr>
					<th>创建时间</th>
					<td><input name="ccreatedatetimeStart" class="easyui-datetimebox" data-options="editable:false" style="width: 155px;" /><s:text name="to"></s:text><input name="ccreatedatetimeEnd" class="easyui-datetimebox" data-options="editable:false" style="width: 155px;" /></td>
				</tr>
				<tr>
					<th>最后修改时间</th>
					<td><input name="cmodifydatetimeStart" class="easyui-datetimebox" data-options="editable:false" style="width: 155px;" /><s:text name="to"></s:text><input name="cmodifydatetimeEnd" class="easyui-datetimebox" data-options="editable:false" style="width: 155px;" />
					
					<a class="easyui-linkbutton  blankSpace" href="javascript:void(0);"  onclick="_search();">查询</a>&nbsp;&nbsp;
					<a class="easyui-linkbutton" href="javascript:void(0);"  onclick="cleanSearch();">重置</a>
					
					</td>
				</tr>
			</table>
			-->
			<div  style="padding:20px; margin: 0px;height: 24px;">
				<span class="title"><s:text name="jueSeMC"></s:text></span>
               	<input type="text" name="jueSeMC" class="t_d  easyui-validatebox"  data-options="validType:'chineseAndEnglish'"  style="width:150px;"/>
               	<span class="title blankSpace"><s:text name="zhuangTai"></s:text></span>
               	<input type="text"  id="zhuangTai" name="zhuangTai" class="t_d"   style="width:150px;" />
					<a class="easyui-linkbutton  blankSpace" href="javascript:void(0);"  onclick="_search();">查询</a>&nbsp;&nbsp;
					<a class="easyui-linkbutton" href="javascript:void(0);"  onclick="cleanSearch();">重置</a>
			</div>
		</form>
	</div>
	
	<div data-options="region:'center',border:false" style="overflow: hidden;">
		<table id="datagrid"></table>
	</div>
	
	<!-- 右键菜单 -->
	<div id="menu" class="easyui-menu" style="width:120px;display: none;">
		<div onclick="append();" data-options="iconCls:'icon-add'"><s:text name="add"></s:text></div>
		<div onclick="edit();" data-options="iconCls:'icon-edit'"><s:text name="edit"></s:text></div>
		<div onclick="remove();" data-options="iconCls:'icon-remove'"><s:text name="delete"></s:text></div>
	</div>
	<!-- 右键菜单 end-->
</body>
</html>